import { IMessageUtil } from '@ibiz-template/runtime';
import { ElMessage } from 'element-plus';

/**
 * 消息通知
 *
 * @author chitanda
 * @date 2022-08-17 16:08:24
 * @export
 * @class MessageUtil
 * @implements {IMessageUtil}
 */
export class MessageUtil implements IMessageUtil {
  info(
    msg: string,
    duration?: number | undefined,
    closable?: boolean | undefined,
  ): void {
    ElMessage.info({
      message: msg,
      duration: duration ? duration * 1000 : duration,
      showClose: closable,
    });
  }

  success(
    msg: string,
    duration?: number | undefined,
    closable?: boolean | undefined,
  ): void {
    ElMessage.success({
      message: msg,
      duration: duration ? duration * 1000 : duration,
      showClose: closable,
    });
  }

  warning(
    msg: string,
    duration?: number | undefined,
    closable?: boolean | undefined,
  ): void {
    ElMessage.warning({
      message: msg,
      duration: duration ? duration * 1000 : duration,
      showClose: closable,
    });
  }

  error(
    msg: string,
    duration?: number | undefined,
    closable?: boolean | undefined,
  ): void {
    ElMessage.error({
      message: msg,
      duration: duration ? duration * 1000 : duration,
      showClose: closable,
    });
  }
}
